/******************************************************************************************
 * Import
 ******************************************************************************************/

// module
import Taro, { Component } from '@tarojs/taro';
import { AtBadge, Image, ScrollView } from 'taro-ui';

// project
import { CPage, CContent, CHeader, CFooter, CFloat, CAround, CBetween, CCenter, CRow, CColumn, CWrap, CLine, CHand, CItemX, CItemY, CText, CLabel, CSvg, CImage, CButton } from '../../../library/comp';
import { Base64, Gen, Time, Zip, Session, Storage, Http, Toast } from '../../../library/func';
import Icon from '../../../project/style/icon';
import DoHttp from '../../../project/func/http/http';

// images

/******************************************************************************************
 * Export Class
 ******************************************************************************************/

export default class HomeList extends Component {

	/*------------------------------------------------------------------------------------
	 * 初始化
	 *-----------------------------------------------------------------------------------*/
	constructor(props) {
		super(props);

		/**
		 * state
		 */
		this.state = {
			data:{}
		}
	}

	/*------------------------------------------------------------------------------------
	 * 生命周期
	 *-----------------------------------------------------------------------------------*/
	// 获取信息
	getInfo(){
		DoHttp.Loading({
			url:'usercenter/home.php',
			success:(data) => {
				// console.log(data);
				this.setState({
					data: data
				},()=>{
					// console.log(this.state.data);
				})
			},
			error:(err) => {
				// console.log(err);
			}
		})
	}

	// didMount
	componentDidMount() {
		this.getInfo();
	}

	// didShow
	componentDidShow(){
		this.getInfo();
	}
	
	/*------------------------------------------------------------------------------------
	 * 事件处理
	 *-----------------------------------------------------------------------------------*/
    // onRedirect
    onRedirect = (url, e)=> {
        wx.redirectTo({
            url: url
        })
		// // console.log(e)
    }

    // onNavigate
    onNavigate = (url, e)=> {
		wx.navigateTo({
			url: url
		})
    }

	/*------------------------------------------------------------------------------------
	 * 自定义方法
	 *-----------------------------------------------------------------------------------*/

	config = {
        navigationBarTitleText: '个人中心',
        navigationBarBackgroundColor: '#dd2f3c',
        navigationBarTextStyle: '#fff'
    }


	// 轻提示
    onToast = ()=> {
		Toast.text('暂未开放此功能');
    }

	/*------------------------------------------------------------------------------------
	 * 渲染
	 *-----------------------------------------------------------------------------------*/
	render () {
		return (
			<CPage style='height:100%' class='f1' >
				{/* CContent并不是高度100%铺满，是有pb='80'撑开的，需改善 */}
				<CContent style='position:relative;height:100%' bg='#f2f2f2' pb='160' mb='100' >
					
					{/* 背景图 star */}
					<CImage  src={'http://image.mod.hesq.com.cn/rushbuy/assets/20181113//me_bg2.png'} w='750' h='380' left='0' top='0' style='position:absolute;' />
					{/* <CRow h='230' left='0' top='0' bg='#dd2f3c'  style='position:absolute;'></CRow> */}
					{/* 背景图 end */}
					
					{/* 主体部分 */}
					<CColumn style='position:relative;width:100%;left:0;top:0px;box-sizing:border-box;height:100%' pl='30' pr='30' pt='60' >
						{/* 头部资料部分 star */}
						<CColumn>
							<CRow style='position:relative'>
								<CHand style='right:0px;position:absolute' onClick={this.onToast}>
									<AtBadge maxValue={99}>
										<CSvg w='40' h='40' color='#fff' bg='#fff' icon={Icon.msg} />
									</AtBadge>
								</CHand>
							</CRow>
							<CRow pb='20'>
								<CHand>
									<CImage src={this.state.data.user[0].object.set_head} lazyLoad={true} w='120' h='120' ra='120' mr='24'/>
								</CHand>
								<CHand>
									<CHand color='#fff' size='34'>{this.state.data.user[0].object.set_nick}</CHand>
								</CHand>
							</CRow>
							<CRow x='right' pr='18'>
								<CText color='#fff' size='30' onClick={this.onNavigate.bind(this,'/screen/user/setting/presenter')} >填写推荐人</CText>
							</CRow>
						</CColumn>
						{/* 头部资料部分 end */}

						{/* 全部订单 star */}
						<CColumn class='homeLine' style='margin-top:40rpx;'>
							<CBetween pa='20 26' bb='1 solid #f2f2f2' onClick={this.onNavigate.bind(this,'/screen/user/order/list?status=全部')} >
								<CText color='#6b6b6b' size='28'>全部订单</CText>
								<CSvg w='30' h='30' color='#c5c5c5' icon={Icon.right} />
							</CBetween>
							<CBetween px='26' pt='24' mb='20' >
								<CItemY x='center' onClick={this.onNavigate.bind(this,'/screen/user/order/list?status=未付款')}>
									{ this.state.data.count_status_1 ? (
										<AtBadge value={this.state.data.count_status_1} maxValue={99}>
											<CSvg w='60' h='60' color='#e71919' icon={Icon.express} />
										</AtBadge>
									) : (
										<CSvg w='60' h='60' color='#de001c' icon={Icon.express} />
									)}
									<CText size='28'>待付款</CText>
								</CItemY>
								<CItemY x='center' onClick={this.onNavigate.bind(this,'/screen/user/order/list?status=未发货')}>
									{ this.state.data.count_status_2 ? (
										<AtBadge value={this.state.data.count_status_2} maxValue={99}>
											<CSvg w='60' h='60' color='#e71919' icon={Icon.express} />
										</AtBadge>
									) : (
										<CSvg w='60' h='60' color='#de001c' icon={Icon.express} />
									)}
									<CText size='28'>待发货</CText>
								</CItemY>
								<CItemY x='center' onClick={this.onNavigate.bind(this,'/screen/user/order/list?status=已发货')}>
									{ this.state.data.count_status_3 ? (
										<AtBadge value={this.state.data.count_status_3} maxValue={99}>
											<CSvg w='60' h='60' color='#e71919' icon={Icon.express} />
										</AtBadge>
									) : (
										<CSvg w='60' h='60' color='#de001c' icon={Icon.express} />
									)}
									<CText size='28'>待收货</CText>
								</CItemY>
								<CItemY x='center' onClick={this.onNavigate.bind(this,'/screen/user/order/list?status=已完成')}>
									{ this.state.data.count_status_4 ? (
										<AtBadge value={this.state.data.count_status_4} maxValue={99}>
											<CSvg w='60' h='60' color='#e71919' icon={Icon.express} />
										</AtBadge>
									) : (
										<CSvg w='60' h='60' color='#de001c' icon={Icon.express} />
									)}
									<CText size='28'>待评价</CText>
								</CItemY>
								<CItemY x='center' onClick={this.onToast}>
									<CSvg w='60' h='60' color='#de001c' icon={Icon.express} />
									<CText size='28'>退换货</CText>
								</CItemY>
							</CBetween>
						</CColumn>
						{/* 全部订单 end */}

						{/* 第二栏 关注、收货地址、帮助 star */}
						<CBetween class='homeLine' px='70' py='30'>
							<CItemY x='center' onClick={this.onNavigate.bind(this,'/screen/user/collect/product')}>
								<CSvg w='50' h='50' color='#e44d1a' icon={Icon["fav-2"]}/>
								<CText size='28' mt='18'>关注</CText>
							</CItemY>
							<CItemY x='center' onClick={this.onNavigate.bind(this,'/screen/user/address/list')} >
								<CSvg w='60' h='60' color='#eca731' icon={Icon.address} />
								<CText size='28' mt='10'>收货地址</CText>
							</CItemY>
							<CItemY x='center' onClick={this.onNavigate.bind(this,'/screen/user/help/list')} >
								<CSvg w='60' h='60' color='#ec5914' icon={Icon.help}/>
								<CText size='28' mt='10'>帮助</CText>
							</CItemY>
						</CBetween>
						{/* 第二栏 关注、收货地址、帮助 end */}
						
					</CColumn>
					{/* 主体部分 end */}

				</CContent>
			</CPage>
		)
	}
}
